/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ucmconfchecker.UI;

import edu.uci.ics.jung.algorithms.layout.Layout;
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.TrayIcon;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import ucmconfchecker.FlabotHandler;
import ucmconfchecker.TraceLogHandler;
import ucmconfchecker.TraceLogReconstruction;
import ucmconfchecker.conformance.*;
import ucmconfchecker.pActivationTrace.ResponsibilityActivationTrace;
import ucmconfchecker.pArchitecture.Architecture;
import ucmconfchecker.pArchitecture.Component;
import ucmconfchecker.pArchitecture.Responsibility;
import ucmconfchecker.pExecutionTrace.ImplEvent;
import ucmconfchecker.pImplementation.EClass;
import ucmconfchecker.pImplementation.EMethod;
import ucmconfchecker.pUCM.UCM;
import ucmconfchecker.pucm2graph.ExcecutionTrace2Events;
import ucmconfchecker.pucm2graph.Ucm2Graph;

/**
 *
 * @author Administrador
 */
public class ApplicationView extends javax.swing.JFrame {

    private  FlabotHandler flabotHandler;
    private TraceLogHandler logHandler;
    
    private ApplicationModel<Responsibility,Component> applicationModel = new ApplicationModel<Responsibility,Component>();
   
    
    EventView traceGanttPanel;
    
    ScenarioView<Responsibility> graphView;
    private String sideTreeSelectedScenario =null;
    private String sideTreeSelectedTrace = null;
       
    private String path= "files/delta 2";
    private Map<String,Layout<Responsibility,Edge>> layouts = new HashMap<String,Layout<Responsibility,Edge>>();
    private String selectedScenario;
    private String selectedTrace;
    
    
    public ApplicationView() {
        initComponents();
        initIcons();
        
        traceGanttPanel = new EventView();
        traceEvaluationPanel.setLayout(new java.awt.BorderLayout());
        traceEvaluationPanel.add(traceGanttPanel, BorderLayout.CENTER);
        
        graphView  =new ScenarioView();
        graphPanel.setLayout(new BorderLayout());
        graphPanel.add(graphView, BorderLayout.CENTER);
        
        
        conformanceTabs.setEnabledAt(1, false);
        conformanceTabs.setEnabledAt(2, false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        jToolBar8 = new javax.swing.JToolBar();
        jToolBar2 = new javax.swing.JToolBar();
        importFlabotMainButton = new javax.swing.JButton();
        loadTraceMainButtton = new javax.swing.JButton();
        jSplitPane2 = new javax.swing.JSplitPane();
        leftTabs = new javax.swing.JTabbedPane();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        architectureTree = new javax.swing.JTree();
        jToolBar5 = new javax.swing.JToolBar();
        loadArchitectureButton = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        ucmTree = new javax.swing.JTree();
        jToolBar6 = new javax.swing.JToolBar();
        showUCMButtton = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        traceTree = new javax.swing.JTree();
        jToolBar7 = new javax.swing.JToolBar();
        loadTraceButtton = new javax.swing.JButton();
        addTraceButtton = new javax.swing.JButton();
        removeTraceButtton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        showTraceButtton = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        sourceTree = new javax.swing.JTree();
        jToolBar10 = new javax.swing.JToolBar();
        loadSourceButton = new javax.swing.JButton();
        conformanceTabs = new javax.swing.JTabbedPane();
        jPanel9 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        jPanel10 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        checkConformanceMissingPreconditions = new javax.swing.JCheckBox();
        checkConformanceMissingEvents = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        checkConformancePrecedence = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        checkConformanceUnexpectedEvents = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        checkStrictPrecedence = new javax.swing.JCheckBox();
        jLabel10 = new javax.swing.JLabel();
        conformanceCheckButton = new javax.swing.JButton();
        globalConformancePanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jSplitPane3 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jToolBar3 = new javax.swing.JToolBar();
        jLabel1 = new javax.swing.JLabel();
        selectScenarioCombo = new javax.swing.JComboBox();
        filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        filler4 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        graphPanel = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jToolBar4 = new javax.swing.JToolBar();
        jLabel2 = new javax.swing.JLabel();
        selectTraceCombo = new javax.swing.JComboBox();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        traceEvaluationPanel = new javax.swing.JPanel();
        jToolBar9 = new javax.swing.JToolBar();
        jProgressBar1 = new javax.swing.JProgressBar();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jToolBar8.setRollover(true);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Conformance Checker");

        jToolBar2.setFloatable(false);
        jToolBar2.setRollover(true);

        importFlabotMainButton.setText("Import Flabot");
        importFlabotMainButton.setFocusable(false);
        importFlabotMainButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        importFlabotMainButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        importFlabotMainButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importFlabotMainButtonActionPerformed(evt);
            }
        });
        jToolBar2.add(importFlabotMainButton);

        loadTraceMainButtton.setText("Import traceLog");
        loadTraceMainButtton.setToolTipText("");
        loadTraceMainButtton.setFocusable(false);
        loadTraceMainButtton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        loadTraceMainButtton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        loadTraceMainButtton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadTraceMainButttonActionPerformed(evt);
            }
        });
        jToolBar2.add(loadTraceMainButtton);

        jSplitPane2.setDividerLocation(301);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Architecture");
        architectureTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane1.setViewportView(architectureTree);

        jToolBar5.setFloatable(false);
        jToolBar5.setRollover(true);

        loadArchitectureButton.setText("Load architecture");
        loadArchitectureButton.setEnabled(false);
        loadArchitectureButton.setFocusable(false);
        loadArchitectureButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        loadArchitectureButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar5.add(loadArchitectureButton);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar5, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
            .addComponent(jScrollPane1)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jToolBar5, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE))
        );

        leftTabs.addTab("Architecture", jPanel5);

        treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("UCMs");
        ucmTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        ucmTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                ucmTreeValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(ucmTree);

        jToolBar6.setFloatable(false);
        jToolBar6.setRollover(true);

        showUCMButtton.setText("Show UCM");
        showUCMButtton.setToolTipText("");
        showUCMButtton.setEnabled(false);
        showUCMButtton.setFocusable(false);
        showUCMButtton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        showUCMButtton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        showUCMButtton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showUCMButttonActionPerformed(evt);
            }
        });
        jToolBar6.add(showUCMButtton);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar6, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
            .addComponent(jScrollPane3)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jToolBar6, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE))
        );

        leftTabs.addTab("Scenarios", jPanel6);

        treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Traces");
        traceTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        traceTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                traceTreeValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(traceTree);

        jToolBar7.setFloatable(false);
        jToolBar7.setRollover(true);

        loadTraceButtton.setText("Load trace");
        loadTraceButtton.setToolTipText("");
        loadTraceButtton.setEnabled(false);
        loadTraceButtton.setFocusable(false);
        loadTraceButtton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        loadTraceButtton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        loadTraceButtton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadTraceButttonActionPerformed(evt);
            }
        });
        jToolBar7.add(loadTraceButtton);

        addTraceButtton.setText("Add Trace");
        addTraceButtton.setToolTipText("");
        addTraceButtton.setFocusable(false);
        addTraceButtton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addTraceButtton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addTraceButtton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addTraceButttonActionPerformed(evt);
            }
        });
        jToolBar7.add(addTraceButtton);

        removeTraceButtton.setText("Remove Trace");
        removeTraceButtton.setToolTipText("");
        removeTraceButtton.setFocusable(false);
        removeTraceButtton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        removeTraceButtton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        removeTraceButtton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeTraceButttonActionPerformed(evt);
            }
        });
        jToolBar7.add(removeTraceButtton);
        jToolBar7.add(jSeparator1);

        showTraceButtton.setText("Show trace");
        showTraceButtton.setToolTipText("");
        showTraceButtton.setFocusable(false);
        showTraceButtton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        showTraceButtton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        showTraceButtton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showTraceButttonActionPerformed(evt);
            }
        });
        jToolBar7.add(showTraceButtton);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar7, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
            .addComponent(jScrollPane2)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jToolBar7, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE))
        );

        leftTabs.addTab("Traces", jPanel7);

        treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Implementation");
        sourceTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane4.setViewportView(sourceTree);

        jToolBar10.setFloatable(false);
        jToolBar10.setRollover(true);

        loadSourceButton.setText("Load Implementation");
        loadSourceButton.setToolTipText("");
        loadSourceButton.setEnabled(false);
        loadSourceButton.setFocusable(false);
        loadSourceButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        loadSourceButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        loadSourceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadSourceButtonActionPerformed(evt);
            }
        });
        jToolBar10.add(loadSourceButton);

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar10, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
            .addComponent(jScrollPane4)
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addComponent(jToolBar10, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE))
        );

        leftTabs.addTab("Implementation", jPanel11);

        jSplitPane2.setLeftComponent(leftTabs);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel10.setName("Configuration"); // NOI18N

        jLabel4.setText("Scenario: Responsibility A must precede B in the traces");

        checkConformanceMissingPreconditions.setText("Missing preconditions");
        checkConformanceMissingPreconditions.setEnabled(false);
        checkConformanceMissingPreconditions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkConformanceMissingPreconditionsActionPerformed(evt);
            }
        });

        checkConformanceMissingEvents.setSelected(true);
        checkConformanceMissingEvents.setText("Missing responsibility activations");
        checkConformanceMissingEvents.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkConformanceMissingEventsActionPerformed(evt);
            }
        });

        jLabel3.setText("Detect:");

        jLabel9.setText("Example: Z found (out of scenario)");

        jLabel7.setText("Example: B not found");

        jLabel8.setText("Example: A not found");

        checkConformancePrecedence.setSelected(true);
        checkConformancePrecedence.setText("Precedence errors");
        checkConformancePrecedence.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkConformancePrecedenceActionPerformed(evt);
            }
        });

        jLabel6.setText("Example: B found before A");

        checkConformanceUnexpectedEvents.setText("Unexpected events");
        checkConformanceUnexpectedEvents.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkConformanceUnexpectedEventsActionPerformed(evt);
            }
        });

        jLabel5.setText("Use:");

        checkStrictPrecedence.setSelected(true);
        checkStrictPrecedence.setText("Strict precedence");
        checkStrictPrecedence.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkStrictPrecedenceActionPerformed(evt);
            }
        });

        jLabel10.setText("A must finish before B starts");

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkConformancePrecedence)
                    .addComponent(jLabel3)
                    .addComponent(checkConformanceMissingEvents)
                    .addComponent(checkConformanceMissingPreconditions)
                    .addComponent(checkConformanceUnexpectedEvents)
                    .addComponent(checkStrictPrecedence)
                    .addComponent(jLabel5))
                .addGap(26, 26, 26)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6))
                .addContainerGap(163, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkConformancePrecedence)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkConformanceMissingEvents)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkConformanceMissingPreconditions)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkConformanceUnexpectedEvents)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(checkStrictPrecedence)
                    .addComponent(jLabel10))
                .addContainerGap())
        );

        conformanceCheckButton.setText("Conformance check");
        conformanceCheckButton.setFocusable(false);
        conformanceCheckButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        conformanceCheckButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        conformanceCheckButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                conformanceCheckButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 665, Short.MAX_VALUE)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(conformanceCheckButton)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 271, Short.MAX_VALUE)
                .addComponent(conformanceCheckButton)
                .addContainerGap())
        );

        conformanceTabs.addTab("Conformance checking", jPanel9);

        javax.swing.GroupLayout globalConformancePanelLayout = new javax.swing.GroupLayout(globalConformancePanel);
        globalConformancePanel.setLayout(globalConformancePanelLayout);
        globalConformancePanelLayout.setHorizontalGroup(
            globalConformancePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 665, Short.MAX_VALUE)
        );
        globalConformancePanelLayout.setVerticalGroup(
            globalConformancePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 536, Short.MAX_VALUE)
        );

        conformanceTabs.addTab("Global statistics", globalConformancePanel);

        jSplitPane3.setDividerLocation(300);
        jSplitPane3.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane3.setOneTouchExpandable(true);
        jSplitPane3.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jSplitPane3ComponentResized(evt);
            }
        });

        jToolBar3.setFloatable(false);
        jToolBar3.setRollover(true);

        jLabel1.setText("Scenario: ");
        jToolBar3.add(jLabel1);

        selectScenarioCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        selectScenarioCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectScenarioComboActionPerformed(evt);
            }
        });
        jToolBar3.add(selectScenarioCombo);
        jToolBar3.add(filler2);
        jToolBar3.add(filler4);

        graphPanel.setPreferredSize(new java.awt.Dimension(200, 218));
        graphPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                graphPanelComponentResized(evt);
            }
        });

        javax.swing.GroupLayout graphPanelLayout = new javax.swing.GroupLayout(graphPanel);
        graphPanel.setLayout(graphPanelLayout);
        graphPanelLayout.setHorizontalGroup(
            graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 643, Short.MAX_VALUE)
        );
        graphPanelLayout.setVerticalGroup(
            graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 268, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(graphPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 643, Short.MAX_VALUE)
            .addComponent(jToolBar3, javax.swing.GroupLayout.DEFAULT_SIZE, 643, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(graphPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE))
        );

        jSplitPane3.setLeftComponent(jPanel2);

        jPanel3.setMaximumSize(new java.awt.Dimension(32767, 300));
        jPanel3.setPreferredSize(new java.awt.Dimension(643, 200));

        jToolBar4.setFloatable(false);
        jToolBar4.setRollover(true);

        jLabel2.setText("Trace: ");
        jToolBar4.add(jLabel2);

        selectTraceCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jToolBar4.add(selectTraceCombo);
        jToolBar4.add(filler1);
        jToolBar4.add(filler3);

        javax.swing.GroupLayout traceEvaluationPanelLayout = new javax.swing.GroupLayout(traceEvaluationPanel);
        traceEvaluationPanel.setLayout(traceEvaluationPanelLayout);
        traceEvaluationPanelLayout.setHorizontalGroup(
            traceEvaluationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 643, Short.MAX_VALUE)
        );
        traceEvaluationPanelLayout.setVerticalGroup(
            traceEvaluationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 169, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(traceEvaluationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jToolBar4, javax.swing.GroupLayout.DEFAULT_SIZE, 643, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jToolBar4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(traceEvaluationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jSplitPane3.setRightComponent(jPanel3);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane3)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jSplitPane3)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        conformanceTabs.addTab("UCM vs Trace", jPanel1);

        jSplitPane2.setRightComponent(conformanceTabs);
        conformanceTabs.getAccessibleContext().setAccessibleName("Conformance check");

        jToolBar9.setFloatable(false);
        jToolBar9.setRollover(true);
        jToolBar9.add(jProgressBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane2)
            .addComponent(jToolBar9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void conformanceCheckButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_conformanceCheckButtonActionPerformed
        checkConformance();
    }//GEN-LAST:event_conformanceCheckButtonActionPerformed

    private void checkConformanceMissingEventsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkConformanceMissingEventsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_checkConformanceMissingEventsActionPerformed

    private void checkConformanceMissingPreconditionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkConformanceMissingPreconditionsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_checkConformanceMissingPreconditionsActionPerformed

    private void checkConformanceUnexpectedEventsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkConformanceUnexpectedEventsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_checkConformanceUnexpectedEventsActionPerformed

    private void selectScenarioComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectScenarioComboActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_selectScenarioComboActionPerformed

    private void importFlabotMainButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importFlabotMainButtonActionPerformed
        openUCM();
    }//GEN-LAST:event_importFlabotMainButtonActionPerformed

    private void loadTraceMainButttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadTraceMainButttonActionPerformed
         openTrace();
    }//GEN-LAST:event_loadTraceMainButttonActionPerformed

    private void showTraceButttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showTraceButttonActionPerformed
        // TODO add your handling code here:
        
        if(getSideTreeSelectedTrace()!=null){
            if(applicationModel.getEventTrace(getSideTreeSelectedTrace())!=null){
                EventTrace<Responsibility> eventTrace = applicationModel.getEventTrace(getSideTreeSelectedTrace());
                EventView.showDialog(this, eventTrace);
            
            }
        }
    }//GEN-LAST:event_showTraceButttonActionPerformed

    private void loadTraceButttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadTraceButttonActionPerformed
        openTrace();
    }//GEN-LAST:event_loadTraceButttonActionPerformed

    private void showUCMButttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showUCMButttonActionPerformed

        if(getSideTreeSelectedScenario()!=null){
            if(applicationModel.getScenario(getSideTreeSelectedScenario())!=null){
                Scenario<Responsibility> scenario = applicationModel.getScenario(getSideTreeSelectedScenario());
                ScenarioView.showDialog(this,scenario,layouts.get(scenario.getName()));
            
            }
        }
    }//GEN-LAST:event_showUCMButttonActionPerformed

    private void loadSourceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadSourceButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_loadSourceButtonActionPerformed

    private void checkConformancePrecedenceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkConformancePrecedenceActionPerformed
       // TODO addg your handling code here:
    }//GEN-LAST:event_checkConformancePrecedenceActionPerformed

    private void ucmTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_ucmTreeValueChanged
        System.out.println("nodeSelected = "+evt.getNewLeadSelectionPath().toString());
        if( evt.getNewLeadSelectionPath().getLastPathComponent()!=null 
         && applicationModel.getScenario(evt.getNewLeadSelectionPath().getLastPathComponent().toString())!=null){
            setSideTreeSelectedScenario(evt.getNewLeadSelectionPath().getLastPathComponent().toString());            
        }else{
            setSideTreeSelectedScenario(null);
        }
    }//GEN-LAST:event_ucmTreeValueChanged

    private void addTraceButttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTraceButttonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_addTraceButttonActionPerformed

    private void removeTraceButttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTraceButttonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_removeTraceButttonActionPerformed

    private void graphPanelComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_graphPanelComponentResized
    }//GEN-LAST:event_graphPanelComponentResized

    private void checkStrictPrecedenceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkStrictPrecedenceActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_checkStrictPrecedenceActionPerformed

    private void traceTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_traceTreeValueChanged
        System.out.println("nodeSelected = "+evt.getNewLeadSelectionPath().toString());
        if( evt.getNewLeadSelectionPath().getLastPathComponent()!=null 
         && applicationModel.getEventTrace(evt.getNewLeadSelectionPath().getLastPathComponent().toString())!=null){
            setSideTreeSelectedTrace(evt.getNewLeadSelectionPath().getLastPathComponent().toString());            
        }else{
            setSideTreeSelectedTrace(null);
        }
    }//GEN-LAST:event_traceTreeValueChanged

    private void jSplitPane3ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jSplitPane3ComponentResized
        jSplitPane3.setDividerLocation(0.7);
    }//GEN-LAST:event_jSplitPane3ComponentResized

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ApplicationView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ApplicationView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ApplicationView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ApplicationView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        java.awt.EventQueue.invokeLater(new Runnable() {
        
            public void run() {
                new ApplicationView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addTraceButtton;
    private javax.swing.JTree architectureTree;
    private javax.swing.JCheckBox checkConformanceMissingEvents;
    private javax.swing.JCheckBox checkConformanceMissingPreconditions;
    private javax.swing.JCheckBox checkConformancePrecedence;
    private javax.swing.JCheckBox checkConformanceUnexpectedEvents;
    private javax.swing.JCheckBox checkStrictPrecedence;
    private javax.swing.JButton conformanceCheckButton;
    private javax.swing.JTabbedPane conformanceTabs;
    private javax.swing.Box.Filler filler1;
    private javax.swing.Box.Filler filler2;
    private javax.swing.Box.Filler filler3;
    private javax.swing.Box.Filler filler4;
    private javax.swing.JPanel globalConformancePanel;
    private javax.swing.JPanel graphPanel;
    private javax.swing.JButton importFlabotMainButton;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JSplitPane jSplitPane3;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar10;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JToolBar jToolBar4;
    private javax.swing.JToolBar jToolBar5;
    private javax.swing.JToolBar jToolBar6;
    private javax.swing.JToolBar jToolBar7;
    private javax.swing.JToolBar jToolBar8;
    private javax.swing.JToolBar jToolBar9;
    private javax.swing.JTabbedPane leftTabs;
    private javax.swing.JButton loadArchitectureButton;
    private javax.swing.JButton loadSourceButton;
    private javax.swing.JButton loadTraceButtton;
    private javax.swing.JButton loadTraceMainButtton;
    private javax.swing.JButton removeTraceButtton;
    private javax.swing.JComboBox selectScenarioCombo;
    private javax.swing.JComboBox selectTraceCombo;
    private javax.swing.JButton showTraceButtton;
    private javax.swing.JButton showUCMButtton;
    private javax.swing.JTree sourceTree;
    private javax.swing.JPanel traceEvaluationPanel;
    private javax.swing.JTree traceTree;
    private javax.swing.JTree ucmTree;
    // End of variables declaration//GEN-END:variables

    private void updateArchitecture() {
        Architecture<Responsibility,Component> architecture = applicationModel.getArchitecture();
        if(architecture!=null){           
            
//            Architecture<Responsibility,Component> architecture = flabotHandler.getArchitecture();
            if(architecture.getComponents()!=null){
                DefaultMutableTreeNode componentsNode = new DefaultMutableTreeNode("Components");
                TreeModel architectureTreeModel = new DefaultTreeModel(componentsNode);
                
                Map<Component,DefaultMutableTreeNode> componentsMap = new HashMap<Component,DefaultMutableTreeNode>();
                for(Component component:architecture.getComponents()){
                    DefaultMutableTreeNode componentNode = new DefaultMutableTreeNode(component);
                    componentsNode.add(componentNode);
                    componentsMap.put(component, componentNode);
                }
                for(Responsibility responsibility:architecture.getResponsibilities()){
                    DefaultMutableTreeNode responsibilityNode = new DefaultMutableTreeNode(responsibility);
                    DefaultMutableTreeNode componentNode = componentsMap.get(responsibility.getComponent());
                    if(componentNode!=null){
                        componentNode.add(responsibilityNode);
                    }else{
                        //inconsistencia
                    }
                }
                architectureTree.setModel(architectureTreeModel);
            }
        } 
    }
    private void updateScenarios() {
        Map<String, Scenario<Responsibility>> scenarios = applicationModel.getScenarios();
        if(scenarios!=null && !scenarios.keySet().isEmpty()){
            DefaultMutableTreeNode scenariosNode = new DefaultMutableTreeNode("Scenarios");
            TreeModel scenariosTreeModel = new DefaultTreeModel(scenariosNode);

            for(String scenarioName : scenarios.keySet()){
                Scenario<Responsibility> scenario = scenarios.get(scenarioName);
                DefaultMutableTreeNode scenarioNode = new DefaultMutableTreeNode(scenario);
                scenariosNode.add(scenarioNode);
                if(scenario.getVertexSet()!=null && !scenario.getVertexSet().isEmpty()){
                    //no hace falta cargarlo todo dado que tiene un visualizador
//                    ScenarioView.showDialog(this,ConformanceChecker.exampleGraph());
                }

            }
            ucmTree.setModel(scenariosTreeModel);
        }    
    }

    private void updateTraces() {
        Map<String, EventTrace<Responsibility>> traces = applicationModel.getEventTraces();
        if(traces!=null){
//            ArchImpMapping mapping = logHandler.getAIMapping();
//            ExecutionTrace trace = logHandler.getTrace();
            
            DefaultMutableTreeNode TraceNode =  new DefaultMutableTreeNode("Traces");
            TreeModel traceTreeModel = new DefaultTreeModel(TraceNode);
            traceTree.setModel(traceTreeModel);
            //reconstruccion del log
//            Reconstruction reconstruction = new TraceLogReconstruction();
//            ResponsibilityActivationTrace respActTrace = reconstruction.execute(trace, mapping);
                        
            for(EventTrace<Responsibility> trace:traces.values()){
                DefaultMutableTreeNode activationsNode = new DefaultMutableTreeNode(trace.getName());
                TraceNode.add(activationsNode);
                for(Event<Responsibility> event:trace){
                    DefaultMutableTreeNode activationNode = new DefaultMutableTreeNode(event.getEvent()==null?"Sin usar":event.getEvent());
                    activationsNode.add(activationNode);
                    activationNode.add(new DefaultMutableTreeNode("inicio: "+event.getRelativeTimeStart()+"ms"));
                    activationNode.add(new DefaultMutableTreeNode("fin: " +event.getRelativeTimeFinish()+"ms"));
                    
                    DefaultMutableTreeNode tracesNode = new DefaultMutableTreeNode("trace");
                    activationNode.add(tracesNode);
                    for(ImplEvent traceI:event.getTrace()){
                        DefaultMutableTreeNode traceNode = new DefaultMutableTreeNode(traceI.getEThread()+ " " +traceI.getEClass()+"@"+traceI.getEObject()+"."+traceI.getEMethod());
                        tracesNode.add(traceNode);
                        traceNode.add(new DefaultMutableTreeNode("Timestamp: "+traceI.getTimeStamp()));
                        traceNode.add(new DefaultMutableTreeNode("Thread: "+traceI.getEThread()));
                        traceNode.add(new DefaultMutableTreeNode("Class: "+traceI.getEClass()));
                        traceNode.add(new DefaultMutableTreeNode("Object: "+traceI.getEObject()));
                        traceNode.add(new DefaultMutableTreeNode("Method: "+traceI.getEMethod()));
                    }
                        
                }
            }
            
            
            //activation Trace
//            for(ArchEvent event: respActTrace){
//                System.out.println(" - "+ event);
//            }
        }
    }
      private void updateImplementation() {
        Collection<EClass> implementation = applicationModel.getImplementation();
        DefaultMutableTreeNode packagesNode =  new DefaultMutableTreeNode("Packages");
        DefaultTreeModel packagesModel = new DefaultTreeModel(packagesNode);
        sourceTree.setModel(packagesModel);
        if(implementation!=null){
            Map<String,DefaultMutableTreeNode> packagesMap = new HashMap<String,DefaultMutableTreeNode>(); 
            for(EClass eClass: implementation){
                DefaultMutableTreeNode packageNode = packagesMap.get(eClass.getPackage());
                if(packageNode==null){
                    String packageName = eClass.getPackage();
                    if(packageName == null) {packageName = "default";}
                    packageNode = new DefaultMutableTreeNode(packageName);
                    packagesMap.put(eClass.getPackage(),packageNode);
                    packagesNode.add(packageNode);
                }
                String className = eClass.getClassName();
                if(className == null) {className = "default";}
                DefaultMutableTreeNode classNode = new DefaultMutableTreeNode(className);
                packageNode.add(classNode);
                for(EMethod method: eClass.getMethods()){
                    DefaultMutableTreeNode methodNode = new DefaultMutableTreeNode(method);
                    classNode.add(methodNode);
                }
                
            }
        }
      }

    private void checkConformance() {

        Map<String, Scenario<Responsibility>> scenarios = applicationModel.getScenarios();
        Map<String, EventTrace<Responsibility>> traces = applicationModel.getEventTraces();
        if(!scenarios.keySet().isEmpty() && !traces.isEmpty()){
//            ArchImpMapping mapping = logHandler.getAIMapping();
//            ExecutionTrace trace = logHandler.getTrace();
//            Reconstruction reconstruction = new TraceLogReconstruction();
//            ResponsibilityActivationTrace respActTrace = reconstruction.execute(trace, mapping);           
 
            applicationModel.setMissingEvent(checkConformanceMissingEvents.isSelected());
            applicationModel.setMissingPrecondition(checkConformanceMissingPreconditions.isSelected());
            applicationModel.setPrecedence(checkConformancePrecedence.isSelected());
            applicationModel.setStrictPrecedence(checkStrictPrecedence.isSelected());
            applicationModel.setUnexpectedEvent(checkConformanceUnexpectedEvents.isSelected());
            

            applicationModel.check();
           
            this.selectedScenario = Utils.firstKey(scenarios);   //first scenario name
            this.selectedTrace = Utils.firstKey(traces);         //first trace name  

            
            Report<Responsibility> report = applicationModel.getConsolidatedReport();
             
            refreshScenarioVsTrace();
            globalConformancePanel.setLayout(new BorderLayout());
            globalConformancePanel.removeAll();
            globalConformancePanel.add(new PieChartView(report), BorderLayout.CENTER);            
        }
        
        conformanceTabs.setSelectedIndex(1);
        
        conformanceTabs.setEnabledAt(1, true);
        conformanceTabs.setEnabledAt(2, true);

    }

    private int SIZE_SMALL = 32;
    private int SIZE_MEDIUM = 48;
    private int SIZE_BIG = 64;
    private void initIcons() {
        assignIcon(loadArchitectureButton,"resources/icons/architecture.png", SIZE_SMALL);
        assignIcon(showUCMButtton,"resources/icons/chart_view.png", SIZE_SMALL);
        assignIcon(loadTraceButtton,"resources/icons/traces.png", SIZE_SMALL);
        assignIcon(loadTraceMainButtton,"resources/icons/traces.png", SIZE_MEDIUM);
        assignIcon(loadSourceButton,"resources/icons/source_java.png", SIZE_SMALL);
        assignIcon(showTraceButtton,"resources/icons/gantt.png", SIZE_SMALL);
        assignIcon(addTraceButtton,"resources/icons/add.png", SIZE_SMALL);
        assignIcon(removeTraceButtton,"resources/icons/remove.png", SIZE_SMALL);
        assignIcon(conformanceCheckButton,"resources/icons/conformance_check.png",SIZE_BIG);
        assignIcon(importFlabotMainButton,"resources/icons/flabot.png",SIZE_MEDIUM);
    }
    private void assignIcon(JButton button, String imageFilePath, int size){
        try {
            Image img = ImageIO.read(new File(imageFilePath)); 
            
            Image newimg = img.getScaledInstance( size, size,  java.awt.Image.SCALE_SMOOTH ) ;  
            button.setIcon(new ImageIcon( newimg ));
            button.setToolTipText(button.getText());
            button.setText("");
            
        } catch (IOException ex) {
            Logger.getLogger(ApplicationView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    private void openUCM() {                                            
        String filePath = null;
        if(path!=null){
            filePath = new File(path).getParent();
        }
        JFileChooser fc = new JFileChooser(filePath);
        int rc = fc.showDialog(null, "Open");
        if (rc == JFileChooser.APPROVE_OPTION)
        {
            File file = fc.getSelectedFile();           
            path = file.getAbsolutePath();
            //levantado del flabot
            flabotHandler = new FlabotHandler(file.getAbsolutePath());
            applicationModel.setArchitecture(flabotHandler.getArchitecture());
            Ucm2Graph ucm2Graph= new Ucm2Graph();
            for(int ucmId=0; ucmId<flabotHandler.getUCMCount();ucmId++){
                UCM ucm = flabotHandler.getUCM(ucmId);
                String scenarioName = "scenario"+ucmId;
                Scenario<Responsibility> scenario = ucm2Graph.asGraph(ucm,scenarioName);
                applicationModel.addScenario(scenario);
                Layout layout = ucm.getLayout();
                layout.setGraph(scenario);
                layouts.put(scenarioName,layout);
                ScenarioView.showDialog(this,scenario,layout);
            }
            //generacion del UCM
            updateArchitecture();
            updateScenarios();
            
            logHandler = null;
        }
    }                                           

    private void openTrace() {                                             
        if(flabotHandler==null){
           JOptionPane.showMessageDialog(this, "You must open a flabot File first","Invalid Flabot File",TrayIcon.MessageType.ERROR.ordinal()); 
        }else{
            String filePath = null;
            if(path!=null){
                filePath = new File(path).getParent();
            }
            JFileChooser fc = new JFileChooser(filePath);
            int rc = fc.showDialog(null, "Open");
            if (rc == JFileChooser.APPROVE_OPTION)
            {
                File file = fc.getSelectedFile();           
                path = file.getAbsolutePath();
                //levantado del flabot
                
                logHandler = new TraceLogHandler(file.getAbsolutePath(),
                                            flabotHandler);
                TraceLogReconstruction reconstruction = new TraceLogReconstruction();
                ExcecutionTrace2Events<Responsibility> excecutionTrace2Events = new ExcecutionTrace2Events<Responsibility>();
                int id =0;
                if(logHandler.getTrace()!=null){
                    ResponsibilityActivationTrace activationTrace = reconstruction.execute(logHandler.getTrace(), logHandler.getAIMapping());
                    EventTrace<Responsibility> eventTrace = excecutionTrace2Events.asEvents(activationTrace,"Trace"+(++id));
                    applicationModel.addEventTrace(eventTrace);
                    EventView.showDialog(this, eventTrace);
                }
                applicationModel.setImplementation(logHandler.getImplementation());
                updateTraces();
                updateImplementation();
            }
        }
    }                                            
   
    private void refreshScenarioVsTrace() {
        Scenario<Responsibility> scenario = applicationModel.getScenarios().get(selectedScenario); //first scenario
        EventTrace<Responsibility> trace = applicationModel.getEventTraces().get(selectedTrace);
        Report<Responsibility> report = applicationModel.getReport(scenario, trace);

        Utils.setItems(selectScenarioCombo, applicationModel.getScenarios().keySet());
        Utils.setItems(selectTraceCombo, applicationModel.getEventTraces().keySet());
        
        traceGanttPanel.setEvents(trace);
        graphView.setGraphLayout(layouts.get(selectedScenario));
        graphView.setGraph(scenario);
        graphView.setReport(report);
        graphView.setTrace(trace);
    }

    public String getSideTreeSelectedScenario() {
        return sideTreeSelectedScenario;
    }

    public void setSideTreeSelectedScenario(String sideTreeSelectedScenario) {
        this.sideTreeSelectedScenario = sideTreeSelectedScenario;
        showUCMButtton.setEnabled(sideTreeSelectedScenario!=null);
    }

    public String getSideTreeSelectedTrace() {
        return sideTreeSelectedTrace;
    }

    public void setSideTreeSelectedTrace(String sideTreeSelectedTrace) {
        this.sideTreeSelectedTrace = sideTreeSelectedTrace;
        showTraceButtton.setEnabled(sideTreeSelectedTrace!=null);
    }
    
}
